package gov.child.dao;

import gov.child.dao.exception.EntityDeleteException;
import gov.child.dao.exception.EntityQueryException;
import gov.child.dao.exception.EntitySaveException;
import gov.child.dao.exception.EntityUpdateException;
import gov.child.entities.po.EDepartment;
import gov.child.entities.vo.Page;

import java.util.List;

/**
 * The interface Department dao. --finish
 *
 * @author fzh
 * @since 2017 /9/9
 */
public interface DepartmentDao extends Pageable{

    /**
     * 查询所有
     *
     * @return the all
     * @throws EntityQueryException the entity query exception
     */
    default List findAll() throws EntityQueryException {
        return findAll(Page.singlePage());
    }

    /**
     * 查询所有（分页）
     *
     * @param page the page
     * @return the all
     * @throws EntityQueryException the entity query exception
     */
    List findAll(Page page) throws EntityQueryException;

    /**
     * 查询部门名称和ID（所有）
     *
     * @return the name and id
     * @throws EntityQueryException the entity query exception
     */
    List findNameAndId() throws EntityQueryException;

    /**
     * 查询部门名称和ID根据<tt>名字关键字</tt>
     *
     * @param keyword the prefix
     * @return the name and id by name
     * @throws EntityQueryException the entity query exception
     */
    List findNameAndIdByKeyword(String keyword) throws EntityQueryException;

    /**
     * 根据ID查询
     *
     * @param id the id
     * @return the by id
     * @throws EntityQueryException the entity query exception
     */
    EDepartment findById(Integer id) throws EntityQueryException;

    List findByDepartmentParentId(Integer id) throws EntityQueryException;

    /**
     * 保存
     *
     * @param department the department
     * @throws EntitySaveException the entity save exception
     */
    void save(EDepartment department) throws EntitySaveException;

    /**
     * 删除
     *
     * @param department the department
     * @throws EntityDeleteException the entity delete exception
     */
    default void delete(EDepartment department) throws EntityDeleteException {
        deleteById(department.getId());
    }

    /**
     * 根据ID删除
     *
     * @param id the id
     * @throws EntityDeleteException the entity delete exception
     */
    void deleteById(Integer id) throws EntityDeleteException;

    /**
     * 更新Department
     *
     * @param department the department
     * @throws EntityUpdateException the entity update exception
     */
    void update(EDepartment department) throws EntityUpdateException;

    List findParentDepartment();
}
